package org.jeecg.modules.job.sub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.job.sub.entity.SubPhaseTitle;
import org.jeecg.modules.job.sub.mapper.SubPhaseTitleMapper;
import org.jeecg.modules.job.sub.service.ISubPhaseTitleService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 阶段题目关系
 * @Author: jeecg-boot
 * @Date:   2022-10-04
 * @Version: V1.0
 */
@Service
public class SubPhaseTitleServiceImpl extends ServiceImpl<SubPhaseTitleMapper, SubPhaseTitle> implements ISubPhaseTitleService {

    @Transactional
    @Override
    public boolean addBatch(SubPhaseTitle entity) {
        for (String id:entity.getIds()){
            // 判断是否存在
            SubPhaseTitle sb=this.getOne(new QueryWrapper(new SubPhaseTitle().setPhaseId(entity.getPhaseId()).setTitleId(id)));
            if (sb==null){
                sb=new SubPhaseTitle().setPhaseId(entity.getPhaseId()).setTitleId(id);
                this.save(sb);
            }
        }
        return true;
    }

    @Override
    public List<SubPhaseTitle> getPhaseTitleList(SubPhaseTitle entity) {
        return this.baseMapper.getPhaseTitleList(entity);
    }
}
